var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        isIPX : app.globalData.isIPX,
        sharedata : {},
        params : {},
        setparams : {},
        options : {},
    },
    onLoad:function(options){
        var self = this;
        
        this.data.options = options;
        var zfid = options.zfid ? options.zfid : (options.scene ? options.scene : 0);

        var postdata = {
            op : 'fxred',
            zfid : zfid,
        };
        app.com.getLocation(self,function(loc){
            postdata.lng = loc.longitude;
            postdata.lat = loc.latitude;

            app.com.auth(function(user){
                app.com.http('fenchen','POST',postdata,0,false,'','',function(res){
                    if (!res.data.errno) {
                        self.setData({
                            setparams : res.data.data.setparams,
                            sharedata : res.data.data.sharedata,
                            params : res.data.data.params,
                            inited : true,
                        });

                    }else{
                        app.com.alert(res.data.message);
                    }
                });
                app.com.setBar(app,self);
            });
        })
       
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        // 关闭下拉刷新
        wx.stopPullDownRefresh();
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    shareit(){
        var self = this;
        if(self.data.params.isneedauth*1 == 1){
            self.loginauth = this.selectComponent('#loginauth');
            self.loginauth.hideauth();
            return false;
        }
        if(self.data.params.submess && wx.requestSubscribeMessage){
            wx.requestSubscribeMessage({
                tmplIds : self.data.params.submess,
                complete : function(){
                    self.selectComponent('#poster').onClose();
                }
            })
        }else{
            self.selectComponent('#poster').onClose();
        }
        
    },
    authed(e){
        var self = this;
        self.setData({
            'params.isneedauth' : 0,
        })
        self.shareit();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})